package com.atues.controller;


import com.atues.domain.ResponseResult;
import com.atues.domain.entity.Article;
import com.atues.service.ArticleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章表(Article)表控制层
 *
 * @author Liqun
 * @since 2024-08-26 11:45:03
 */
@RestController
@RequestMapping("article")
//@MapperScan("com.")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("list")
    public List<Article> test(){
        return articleService.list();
    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
         return  articleService.getHotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
       return   articleService.articleList(pageNum, pageSize, categoryId);

    }

    @GetMapping("/{id}")
    public ResponseResult articleDetail(@PathVariable Long id){
        return   articleService.getArticleDetail(id);

    }

    @DeleteMapping("deleteArticle/{id}")
    public ResponseResult deleteArticle(@PathVariable String id){
        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        Long articleId = Long.parseLong(id);
        wrapper.eq(articleId>100,Article::getId,articleId);
        if(articleService.remove(wrapper))
            return ResponseResult.okResult(null);
        return ResponseResult.errorResult(0, null);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }


}

